package com.my.screenadapter.mvp;

import android.os.Handler;
import android.os.Looper;

/**
 * Created by zhangyingjie on 2019-12-06
 *
 * @function
 *
 * 负责 M V P
 * 负责 管理 view 响应 module
 */
public class MainPresenter {
    IMainView mainView;
    TaskManager taskData;

    public MainPresenter() {
        this.taskData = new TaskManager(new TaskDataSourceImpl());
    }

    public MainPresenter test() {
        this.taskData = new TaskManager(new TaskDataSourceTestImpl());
        return this;
    }

    public MainPresenter addTaskListener(IMainView viewListener) {
        this.mainView = viewListener;
        return this;
    }

    public void getStringAndShow() {
        //确保 在UI 线程执行
        final Handler mainHandler = new Handler(Looper.getMainLooper());
        new Thread(){
            @Override
            public void run() {
                // TODO: 2019-12-06 getData
                final String str = taskData.getShowContent();
                super.run();
                mainHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mainView.onShowString(str);
                    }
                });
            }
        }.start();
    }

}
